package com.http.servletrequestlistener;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

import static java.lang.Thread.sleep;

@WebServlet(urlPatterns = "/listener")
public class TestListener extends HttpServlet {

    @Override
    public void init() throws ServletException {
        System.out.println("Servlet开始创建。。。");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 使用sleep函数，模拟业务处理
        try {
            sleep(6000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        System.out.println("开始处理业务。。。。");
    }

    @Override
    public void destroy() {
        System.out.println("Servlet开始销毁。。。");
    }
}
